package filter;

import org.omg.PortableInterceptor.INACTIVE;

import javax.servlet.*;
import java.io.IOException;
import java.util.Enumeration;

/**
 * 05-Filter相关配置
 * ①初始化参数
 */
public class Demo03Filter implements Filter {

    private String encoding;


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        encoding = filterConfig.getInitParameter("encoding");
        System.out.println("encoding = " + encoding);

        Enumeration<String> initParameterNames = filterConfig.getInitParameterNames();
        while (initParameterNames.hasMoreElements()) {
            String initParameterName = initParameterNames.nextElement();
            String initParameterValue = filterConfig.getInitParameter(initParameterName);
            System.out.println("initParameterName = " + initParameterName + " , initParameterValue = " + initParameterValue);

        }

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        System.out.println("encoding = " + encoding);
        chain.doFilter(request, response);//相当于执行Demo01Servlet

    }
}
